package com.test.practice.annotation.mateannotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class ProcessTool {
    /**
     * 根据类名获取这个类的方法中有MyTag注解的方法,并获取该注解内容
     * @param clazz
     */
    public static void process(String clazz) {
        Class<?> targetClass = null;

        try {
            targetClass = Class.forName(clazz);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        for (Method m : targetClass.getMethods()) {
            if (m.isAnnotationPresent(MyTag.class)) {
                MyTag tag = m.getAnnotation(MyTag.class);
                System.out.println("方法" + m.getName() + "的MyTag注解内容是:" + tag.name() + "," + tag.age());
            }
        }

        System.out.println("================================================");

        Method[] methods = targetClass.getMethods();
        for (Method method : methods) {

            Annotation[] annotations = method.getAnnotations();
            for (Annotation annotation : annotations) {
                if (annotation instanceof MyTag) {
                    MyTag tag = (MyTag)annotation;
                    System.out.println("方法的MyTag注解内容是:" + tag.name() + "," + tag.age());
                }
            }

        }


    }
}
